/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jBeatsUserReviews.java
 *
 * Created on Nov 11, 2012, 5:22:07 PM
 */
package cs341.cs.uwosh.edu.jBeats;

/**
 *
 * @author haibut41
 */
public class jBeatsUserReviews extends javax.swing.JFrame {

    
        FrameCreator FC = new FrameCreator();
     String user = null;
    User[] userList = null;
    String[] usernameList;
    /** Creates new form jBeatsUser */
    
    
    public jBeatsUserReviews(String user) {
        initComponents();

        //generate list of users
        this.user = user;
        String[] reviews = DatabaseInfo.getUserReviews(user);
        for(int i = 0; i < reviews.length; i++){
            reviewsBox.append(reviews[i]+"\n\n");
        }
        
        userList = DatabaseInfo.getUserList();
        usernameList = new String[userList.length];
        
        
        for(int i=0;i<userList.length;i++){
            usernameList[i] = userList[i].getUserName();
        }
        UserReviewsList.setModel(new javax.swing.DefaultComboBoxModel(usernameList));

    }
        
        
   
     
    /** Creates new form jBeatsUserReviews */


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        userReviewPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        UserReviewsList = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        reviewsBox = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        userReviewPanel.setBackground(new java.awt.Color(84, 131, 161));
        userReviewPanel.setName("userReviewPanel"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        UserReviewsList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        UserReviewsList.setName("UserReviewsList"); // NOI18N
        UserReviewsList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                UserReviewsListMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(UserReviewsList);

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        reviewsBox.setColumns(20);
        reviewsBox.setEditable(false);
        reviewsBox.setLineWrap(true);
        reviewsBox.setRows(5);
        reviewsBox.setName("reviewsBox"); // NOI18N
        jScrollPane2.setViewportView(reviewsBox);

        jLabel1.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N
        jLabel1.setText("User Reviews");
        jLabel1.setName("jLabel1"); // NOI18N

        javax.swing.GroupLayout userReviewPanelLayout = new javax.swing.GroupLayout(userReviewPanel);
        userReviewPanel.setLayout(userReviewPanelLayout);
        userReviewPanelLayout.setHorizontalGroup(
            userReviewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(userReviewPanelLayout.createSequentialGroup()
                .addGroup(userReviewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(userReviewPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 386, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(userReviewPanelLayout.createSequentialGroup()
                        .addGap(202, 202, 202)
                        .addComponent(jLabel1)))
                .addContainerGap())
        );
        userReviewPanelLayout.setVerticalGroup(
            userReviewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, userReviewPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 38, Short.MAX_VALUE)
                .addGroup(userReviewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 261, Short.MAX_VALUE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(userReviewPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(userReviewPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void UserReviewsListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_UserReviewsListMouseClicked
   String current =  (String)UserReviewsList.getSelectedValue();
   String[] reviews = DatabaseInfo.getUserReviews(current);
   reviewsBox.setText("");
   for(int i = 0; i < reviews.length; i++){
        reviewsBox.append(reviews[i]+"\n\n");
   }
   
}//GEN-LAST:event_UserReviewsListMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(jBeatsUserReviews.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(jBeatsUserReviews.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(jBeatsUserReviews.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(jBeatsUserReviews.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                //new jBeatsUserReviews().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JList UserReviewsList;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea reviewsBox;
    private javax.swing.JPanel userReviewPanel;
    // End of variables declaration//GEN-END:variables
}
